<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>直升机最大起飞重量计算器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        .header {
            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }

        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
            font-weight: 300;
        }

        .header p {
            font-size: 1.1em;
            opacity: 0.9;
        }

        .main-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
            padding: 30px;
        }

        .input-section {
            background: #f8f9fa;
            padding: 25px;
            border-radius: 10px;
            border: 1px solid #e9ecef;
        }

        .input-section h2 {
            color: #2c3e50;
            margin-bottom: 20px;
            font-size: 1.5em;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #34495e;
        }

        .form-group input {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        .form-group input:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
        }

        .equipment-section {
            margin-top: 25px;
        }

        .equipment-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 15px;
        }

        .equipment-item {
            display: flex;
            align-items: center;
            padding: 8px;
            background: white;
            border-radius: 5px;
            border: 1px solid #ddd;
        }

        .equipment-item input[type="checkbox"] {
            margin-right: 8px;
            transform: scale(1.2);
        }

        .equipment-item label {
            font-size: 0.9em;
            margin: 0;
            cursor: pointer;
        }

        .calculate-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            transition: transform 0.2s, box-shadow 0.2s;
            margin-top: 20px;
        }

        .calculate-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(52, 152, 219, 0.3);
        }

        .results-section {
            background: #f8f9fa;
            padding: 25px;
            border-radius: 10px;
            border: 1px solid #e9ecef;
        }

        .result-card {
            background: white;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 15px;
            border-left: 4px solid #3498db;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }

        .result-value {
            font-size: 2em;
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 5px;
        }

        .result-unit {
            color: #7f8c8d;
            font-size: 0.9em;
        }

        .warning {
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            color: #856404;
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
        }

        .warning-icon {
            color: #f39c12;
            margin-right: 8px;
        }


        @media (max-width: 768px) {
            .main-content {
                grid-template-columns: 1fr;
                gap: 20px;
                padding: 20px;
            }
            
            .equipment-grid {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 2em;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🚁 直升机最大起飞重量计算器</h1>
            <p>A类垂直操作地面直升机场 - 最大起飞和着陆总重量</p>
        </div>

        <div class="main-content">
            <div class="input-section">
                <h2>📊 输入参数</h2>
                
                <div class="form-group">
                    <label for="pressureAltitude">气压高度 (英尺)</label>
                    <input type="number" id="pressureAltitude" placeholder="例如: 0" min="-1000" max="6000" step="100">
                </div>

                <div class="form-group">
                    <label for="temperature">外部空气温度 (°C)</label>
                    <input type="number" id="temperature" placeholder="例如: 20" min="0" max="52" step="1">
                </div>

                <div class="equipment-section">
                    <h3>🔧 设备配置 (重量减少)</h3>
                    <div class="equipment-grid">
                        <div class="equipment-item">
                            <input type="checkbox" id="doorsOpen" data-weight="120">
                            <label for="doorsOpen">外滑门开启 (-120 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="doorsClosed" data-weight="50">
                            <label for="doorsClosed">外滑门关闭 (-50 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="noseCamera" data-weight="35">
                            <label for="noseCamera">机头摄像头 (-35 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="thommenSearchlight" data-weight="75">
                            <label for="thommenSearchlight">THOMMEN HSL-1600 (-75 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="sx7Searchlight" data-weight="35">
                            <label for="sx7Searchlight">SX-7 STARSUN (-35 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="sx16Searchlight" data-weight="75">
                            <label for="sx16Searchlight">SX-16 NIGHTSUN (-75 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="flirCamera" data-weight="50">
                            <label for="flirCamera">FLIR STAR SAFIRE HD (-50 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="lifeRafts" data-weight="60">
                            <label for="lifeRafts">外置救生筏 (-60 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="utilityHoist" data-weight="115">
                            <label for="utilityHoist">实用绞车 (-115 lbs)</label>
                        </div>
                        <div class="equipment-item">
                            <input type="checkbox" id="bifilar" data-weight="35">
                            <label for="bifilar">可选5P双线 (-35 lbs)</label>
                        </div>
                    </div>
                </div>

                <button class="calculate-btn" onclick="calculateWeight()">
                     计算最大起飞重量
                </button>
            </div>

            <div class="results-section">
                <h2>📈 计算结果</h2>
                
                <div id="results" style="display: none;">
                    <div class="result-card">
                        <div class="result-value" id="maxWeightLbs">0</div>
                        <div class="result-unit">磅 (lbs)</div>
                    </div>
                    
                    <div class="result-card">
                        <div class="result-value" id="maxWeightKg">0</div>
                        <div class="result-unit">千克 (kg)</div>
                    </div>

                    <div class="result-card">
                        <div style="font-size: 1.2em; color: #2c3e50; margin-bottom: 10px;">📊 详细信息</div>
                        <div style="color: #7f8c8d; line-height: 1.6;">
                            <div>密度高度: <span id="densityAltitude">0</span> ft</div>
                            <div>基础最大重量: <span id="baseWeight">0</span> lbs</div>
                            <div>设备重量减少: <span id="equipmentReduction">0</span> lbs</div>
                        </div>
                    </div>

                    <div id="warnings"></div>
                </div>

            </div>
        </div>
    </div>

    <script>
        // 基于图表实际线条的精确数据点
        // 这些数据点需要从图表中精确读取每条等温线与不同气压高度的交点
        const chartData = {
            // 气压高度 (x1000 ft)
            pressureAltitudes: [-1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
            
            // 温度线 (°C) - 对应图表中的斜线
            temperatureLines: {
                '0_AND_BELOW': {
                    name: '0°C及以下',
                    points: [
                        {alt: -1, weight: 11.5}, {alt: 0, weight: 11.5}, {alt: 1, weight: 11.5},
                        {alt: 2, weight: 11.4}, {alt: 3, weight: 11.3}, {alt: 4, weight: 11.15},
                        {alt: 5, weight: 11.0}, {alt: 6, weight: 10.85}
                    ]
                },
                '10': {
                    name: '10°C',
                    points: [
                        {alt: -1, weight: 11.3}, {alt: 0, weight: 11.3}, {alt: 1, weight: 11.2},
                        {alt: 2, weight: 11.1}, {alt: 3, weight: 10.95}, {alt: 4, weight: 10.8},
                        {alt: 5, weight: 10.65}, {alt: 6, weight: 10.5}
                    ]
                },
                '20': {
                    name: '20°C',
                    points: [
                        {alt: -1, weight: 11.1}, {alt: 0, weight: 11.1}, {alt: 1, weight: 10.95},
                        {alt: 2, weight: 10.8}, {alt: 3, weight: 10.65}, {alt: 4, weight: 10.5},
                        {alt: 5, weight: 10.35}, {alt: 6, weight: 10.2}
                    ]
                },
                '30': {
                    name: '30°C',
                    points: [
                        {alt: -1, weight: 10.9}, {alt: 0, weight: 10.85}, {alt: 1, weight: 10.7},
                        {alt: 2, weight: 10.5}, {alt: 3, weight: 10.35}, {alt: 4, weight: 10.2},
                        {alt: 5, weight: 10.05}, {alt: 6, weight: 9.9}
                    ]
                },
                '40': {
                    name: '40°C',
                    points: [
                        {alt: -1, weight: 10.7}, {alt: 0, weight: 10.6}, {alt: 1, weight: 10.45},
                        {alt: 2, weight: 10.3}, {alt: 3, weight: 10.1}, {alt: 4, weight: 9.95},
                        {alt: 5, weight: 9.8}, {alt: 6, weight: 9.65}
                    ]
                },
                '45': {
                    name: '45°C',
                    points: [
                        {alt: -1, weight: 10.5}, {alt: 0, weight: 10.4}, {alt: 1, weight: 10.25},
                        {alt: 2, weight: 10.1}, {alt: 3, weight: 9.9}, {alt: 4, weight: 9.75},
                        {alt: 5, weight: 9.6}, {alt: 6, weight: 9.45}
                    ]
                },
                '50': {
                    name: '50°C',
                    points: [
                        {alt: -1, weight: 10.3}, {alt: 0, weight: 10.2}, {alt: 1, weight: 10.05},
                        {alt: 2, weight: 9.9}, {alt: 3, weight: 9.7}, {alt: 4, weight: 9.55},
                        {alt: 5, weight: 9.4}, {alt: 6, weight: 9.25}
                    ]
                },
                '52': {
                    name: '52°C',
                    points: [
                        {alt: -1, weight: 10.2}, {alt: 0, weight: 10.1}, {alt: 1, weight: 9.95},
                        {alt: 2, weight: 9.8}, {alt: 3, weight: 9.6}, {alt: 4, weight: 9.45},
                        {alt: 5, weight: 9.3}, {alt: 6, weight: 9.15}
                    ]
                }
            },
            
            // 限制线
            limits: {
                densityAltitudeLimit: 5.2, // 5200 ft (5.2 x 1000 ft)
                maxPermittedWeight: 11.5,  // 11500 lbs (11.5 x 1000 lbs)
                
                // 高温限制线 (需要从图表中精确读取)
                highTempLimit: {
                    // 实线 - 高环境温度限制
                    solid: [
                        {alt: 1, weight: 10.2}, {alt: 2, weight: 10.0}, {alt: 3, weight: 9.8},
                        {alt: 4, weight: 9.6}, {alt: 5, weight: 9.4}, {alt: 6, weight: 9.2}
                    ],
                    // 虚线 - 高环境温度限制（高温套件）
                    dashed: [
                        {alt: 1, weight: 10.0}, {alt: 2, weight: 9.8}, {alt: 3, weight: 9.6},
                        {alt: 4, weight: 9.4}, {alt: 5, weight: 9.2}, {alt: 6, weight: 9.0}
                    ]
                }
            }
        };


        // 基于图表实际线条的插值函数
        function interpolateWeight(pressureAltitude1000ft, temperatureC) {
            // 边界检查
            if (pressureAltitude1000ft < -1 || pressureAltitude1000ft > 6 ||
                temperatureC < 0 || temperatureC > 52) {
                return null;
            }

            // 确定温度线
            let tempLine1, tempLine2, tempRatio = 0;
            
            if (temperatureC <= 0) {
                tempLine1 = chartData.temperatureLines['0_AND_BELOW'];
                tempLine2 = chartData.temperatureLines['0_AND_BELOW'];
            } else if (temperatureC <= 10) {
                tempLine1 = chartData.temperatureLines['0_AND_BELOW'];
                tempLine2 = chartData.temperatureLines['10'];
                tempRatio = temperatureC / 10;
            } else if (temperatureC <= 20) {
                tempLine1 = chartData.temperatureLines['10'];
                tempLine2 = chartData.temperatureLines['20'];
                tempRatio = (temperatureC - 10) / 10;
            } else if (temperatureC <= 30) {
                tempLine1 = chartData.temperatureLines['20'];
                tempLine2 = chartData.temperatureLines['30'];
                tempRatio = (temperatureC - 20) / 10;
            } else if (temperatureC <= 40) {
                tempLine1 = chartData.temperatureLines['30'];
                tempLine2 = chartData.temperatureLines['40'];
                tempRatio = (temperatureC - 30) / 10;
            } else if (temperatureC <= 45) {
                tempLine1 = chartData.temperatureLines['40'];
                tempLine2 = chartData.temperatureLines['45'];
                tempRatio = (temperatureC - 40) / 5;
            } else if (temperatureC <= 50) {
                tempLine1 = chartData.temperatureLines['45'];
                tempLine2 = chartData.temperatureLines['50'];
                tempRatio = (temperatureC - 45) / 5;
            } else if (temperatureC <= 52) {
                tempLine1 = chartData.temperatureLines['50'];
                tempLine2 = chartData.temperatureLines['52'];
                tempRatio = (temperatureC - 50) / 2;
            } else {
                tempLine1 = chartData.temperatureLines['52'];
                tempLine2 = chartData.temperatureLines['52'];
            }

            // 在两条温度线之间插值
            const weight1 = interpolateAlongTemperatureLine(tempLine1, pressureAltitude1000ft);
            const weight2 = interpolateAlongTemperatureLine(tempLine2, pressureAltitude1000ft);

            if (weight1 === null || weight2 === null) {
                return null;
            }

            // 线性插值
            return weight1 * (1 - tempRatio) + weight2 * tempRatio;
        }

        // 沿单条温度线插值
        function interpolateAlongTemperatureLine(tempLine, pressureAltitude1000ft) {
            const points = tempLine.points;
            
            // 找到插值区间
            for (let i = 0; i < points.length - 1; i++) {
                const alt1 = points[i].alt;
                const alt2 = points[i + 1].alt;
                
                if (pressureAltitude1000ft >= alt1 && pressureAltitude1000ft <= alt2) {
                    const weight1 = points[i].weight * 1000; // 转换为磅
                    const weight2 = points[i + 1].weight * 1000;
                    
                    const ratio = (pressureAltitude1000ft - alt1) / (alt2 - alt1);
                    return weight1 * (1 - ratio) + weight2 * ratio;
                }
            }
            
            return null;
        }

        // 检查是否在高温套件区域
        function isInHighTempKitArea(pressureAltitude1000ft, temperatureC) {
            const solidLimit = chartData.limits.highTempLimit.solid;
            const dashedLimit = chartData.limits.highTempLimit.dashed;
            
            // 找到对应的限制线点
            let solidWeight = null, dashedWeight = null;
            
            for (let i = 0; i < solidLimit.length - 1; i++) {
                const alt1 = solidLimit[i].alt;
                const alt2 = solidLimit[i + 1].alt;
                
                if (pressureAltitude1000ft >= alt1 && pressureAltitude1000ft <= alt2) {
                    const weight1 = solidLimit[i].weight * 1000;
                    const weight2 = solidLimit[i + 1].weight * 1000;
                    const ratio = (pressureAltitude1000ft - alt1) / (alt2 - alt1);
                    solidWeight = weight1 * (1 - ratio) + weight2 * ratio;
                    break;
                }
            }
            
            for (let i = 0; i < dashedLimit.length - 1; i++) {
                const alt1 = dashedLimit[i].alt;
                const alt2 = dashedLimit[i + 1].alt;
                
                if (pressureAltitude1000ft >= alt1 && pressureAltitude1000ft <= alt2) {
                    const weight1 = dashedLimit[i].weight * 1000;
                    const weight2 = dashedLimit[i + 1].weight * 1000;
                    const ratio = (pressureAltitude1000ft - alt1) / (alt2 - alt1);
                    dashedWeight = weight1 * (1 - ratio) + weight2 * ratio;
                    break;
                }
            }
            
            if (solidWeight === null || dashedWeight === null) {
                return false;
            }
            
            // 计算当前条件下的最大重量
            const currentMaxWeight = interpolateWeight(pressureAltitude1000ft, temperatureC);
            
            // 检查是否在高温套件区域（在两条限制线之间）
            return currentMaxWeight <= solidWeight && currentMaxWeight >= dashedWeight;
        }

        function calculateWeight() {
            const pressureAltitude = parseFloat(document.getElementById('pressureAltitude').value);
            const temperature = parseFloat(document.getElementById('temperature').value);

            if (isNaN(pressureAltitude) || isNaN(temperature)) {
                alert('请输入有效的气压高度和温度值');
                return;
            }

            const pressureAltitude1000ft = pressureAltitude / 1000.0;
            const baseWeight = interpolateWeight(pressureAltitude1000ft, temperature);

            if (baseWeight === null) {
                alert('输入参数超出图表范围');
                return;
            }

            // 计算设备重量减少
            let totalReduction = 0;
            const checkboxes = document.querySelectorAll('.equipment-item input[type="checkbox"]:checked');
            checkboxes.forEach(checkbox => {
                totalReduction += parseInt(checkbox.dataset.weight);
            });

            // 应用重量减少规则（完全按照图表说明）
            let finalWeight = baseWeight;
            if (totalReduction > 0) {
                // 按照图表说明：从总和中减去500磅
                const reductionAmount = totalReduction - 500;
                if (reductionAmount > 0) {
                    // 如果结果为正，从最大总重量中减去此值
                    finalWeight = baseWeight - reductionAmount;
                }
                // 如果结果为负，不需要减少
            }

            // 计算密度高度
            const densityAltitude = pressureAltitude + 120 * (temperature - 15);

            // 显示结果
            document.getElementById('maxWeightLbs').textContent = Math.round(finalWeight);
            document.getElementById('maxWeightKg').textContent = Math.round(finalWeight * 0.453592);
            document.getElementById('densityAltitude').textContent = Math.round(densityAltitude);
            document.getElementById('baseWeight').textContent = Math.round(baseWeight);
            document.getElementById('equipmentReduction').textContent = totalReduction;

            // 检查警告（基于图表实际限制）
            const warnings = [];
            
            // 密度高度限制检查
            if (densityAltitude > 5200) {
                warnings.push('⚠️ 密度高度超过5200英尺限制');
            }
            
            // 高温套件区域检查（基于图表实际线条）
            if (isInHighTempKitArea(pressureAltitude1000ft, temperature)) {
                warnings.push('⚠️ 此操作需要高温套件 (HIGH TEMPERATURE KIT)');
            }
            
            // 参数范围检查
            if (pressureAltitude1000ft < -1 || pressureAltitude1000ft > 6) {
                warnings.push('⚠️ 气压高度超出图表范围 (-1000 to 6000 ft)');
            }
            if (temperature < 0 || temperature > 52) {
                warnings.push('⚠️ 温度超出图表范围 (0 to 52°C)');
            }
            
            // 最大重量限制检查
            if (finalWeight > 11500) {
                warnings.push('⚠️ 重量超过最大允许起飞和着陆重量 (11,500 lbs)');
            }

            // 显示警告
            const warningsDiv = document.getElementById('warnings');
            if (warnings.length > 0) {
                warningsDiv.innerHTML = '<div class="warning"><span class="warning-icon">⚠️</span>' + 
                    warnings.join('<br>') + '</div>';
            } else {
                warningsDiv.innerHTML = '';
            }

            document.getElementById('results').style.display = 'block';
        }

    </script>
</body>
</html>
